//
//  BNTabMainTableView.swift
//  BNUQuoteTrade
//
//  Created by bebull on 2021/12/22.
//

import Foundation
import UIKit

class BNTabMainTableView: UITableView, UIGestureRecognizerDelegate {
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        
        if gestureRecognizer.isKind(of: UIPanGestureRecognizer.self),
            otherGestureRecognizer.isKind(of: UIPanGestureRecognizer.self) {
            guard let otherGesture = otherGestureRecognizer as? UIPanGestureRecognizer else {
                return false
            }
            let otherY = otherGesture.translation(in: self.superview).y
            let otherX = otherGesture.translation(in: self.superview).x
            
            if (otherY == 0.0 && otherX != 0.0) || self.tableHeaderView == nil {
                return false
            } else {
                if otherGestureRecognizer.view != gestureRecognizer.view,
                   gestureRecognizer.view?.bounds.size.width != otherGestureRecognizer.view?.bounds.size.width {
                    return false
                }
                
                if abs(otherY) / abs(otherX) >= 2.0 || otherX == 0.0 {
                    if gestureRecognizer.state == .changed, otherGestureRecognizer.state == .began {
                        return false
                    }
                    return true
                } else {
                    return false
                }
            }
            
        }
        return false
    }
    
}
